﻿using System.Configuration;

namespace SmallDataBase.DTO
{
    /// <summary>
    /// 配置对象
    /// </summary>
    public class ConfigDTO
    {
        /// <summary>
        /// 链接字符串
        /// </summary>
        public string ConnectionString { get; set; }

        /// <summary>
        /// 数据库类型
        /// </summary>
        public DataBaseType DataBaseType { get; set; }

        //自构造函数
        public static ConfigDTO CreateInstance()
        {
            var config = new ConfigDTO
                             {ConnectionString = ConfigurationManager.ConnectionStrings["SmallDataBase"].ToString()};
            string type = ConfigurationManager.AppSettings["SmallDataBaseType"];
            switch (type.ToLower())
            {
                case "mysql":
                    config.DataBaseType = DataBaseType.MySQL;
                    break;
                case "sqlserver2000":
                    config.DataBaseType = DataBaseType.SQLServer2000;
                    break;
                default:
                    config.DataBaseType = DataBaseType.SQLServer2000;
                    break;
            }
            return config;
        }

        private ISQLBuilder _builder;
        /// <summary>
        /// 获取SQLBuilder
        /// </summary>
        /// <returns></returns>
        public ISQLBuilder GetSQLBuilder()
        {
            if (_builder == null)
            {
                switch (DataBaseType)
                {
                    case DTO.DataBaseType.MySQL:
                        _builder = new MySQL.SQLBuilder();
                        break;
                    case DTO.DataBaseType.SQLServer2000:
                        break;
                }
            }
            return _builder;
        }
    }

    /// <summary>
    /// 数据库类型
    /// </summary>
    public enum DataBaseType
    {
        MySQL,
        SQLServer2000
    }
}